Conversation
Allow `defaultConsent` to accept an array of GCMv2 states; each entry fires its own `['consent','default', …]` push onto the dataLayer before `gtm.js`, matching Google's documented multi-call pattern for region- specific defaults. - Widen `GoogleTagManagerOptions.defaultConsent` from a loose `record(string, string|number)` to the canonical `union(gcmConsentState, array(gcmConsentState))`. Drive-by tightening: unknown keys now fail dev-mode schema validation. - Augment shared `ConsentState` with the already-runtime-supported `region: string[]` and `wait_for_update: number` fields. - Add three tests: array ordering vs. `gtm.js`, single-entry-array == bare-object equivalence, and empty-array no-op. Backwards compatible: existing single-object callers behave identically. Refs: https://developers.google.com/tag-platform/security/guides/consent
Allow `defaultConsent` on `useScriptGoogleAnalytics` to accept an array
of GCMv2 states; each entry fires its own `gtag('consent','default', …)`
before `gtag('js', …)`, matching Google's documented multi-call pattern
for region-specific defaults.
- Widen `GoogleAnalyticsOptions.defaultConsent` to
`union(gcmConsentState, array(gcmConsentState))`.
- Add three tests mirroring the GTM suite: array ordering vs.
`gtag('js', …)`, single-entry-array == bare-object equivalence, and
empty-array no-op. Also closes a pre-existing gap where GA had no
consent-ordering test at all.
Backwards compatible: existing single-object callers behave identically.
Refs: https://developers.google.com/tag-platform/security/guides/consent
…nt defaults - Document the new array form of `defaultConsent` on both `useScriptGoogleAnalytics` and `useScriptGoogleTagManager` pages, including a per-region worked example using `region` and `wait_for_update`. - Add `examples/regional-consent` (mirrors `examples/cookie-consent`) showing an EEA-denied + global-granted setup. - Link the new example from both doc pages alongside the existing StackBlitz callouts.
|
@zizzfizzix is attempting to deploy a commit to the Nuxt Team on Vercel. A member of the Team first needs to authorize it. |
commit: |
📝 WalkthroughWalkthroughThis pull request adds support for array-based Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 👉 Get your free trial and get 200 agent minutes per Slack user (a $50 value). Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (1)
examples/regional-consent/package.json (1)
11-15: ⚡ Quick winPin
@nuxt/scriptsinstead oflatest.This example will drift independently of the repo if the module resolves to a moving target, which can break install/preview reproducibility.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@examples/regional-consent/package.json` around lines 11 - 15, The dependency "@nuxt/scripts" in package.json is set to the moving tag "latest"; replace that with a pinned version string (an exact version like "x.y.z" or the same version used elsewhere in the repo) to ensure reproducible installs—update the "@nuxt/scripts" entry to a fixed version instead of "latest".
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/script/src/registry-types.json`:
- Around line 1634-1638: The "defaultConsent" entry's description was truncated
ending with a dangling "See:"; update the description field for the
defaultConsent property to include the missing reference text (or remove the
trailing "See:" and append the full documentation link or explanatory sentence)
so the metadata is complete and meaningful, and ensure the JSON string is
properly escaped and the registry-types.json remains valid JSON.
In `@packages/script/src/runtime/registry/google-tag-manager.ts`:
- Around line 144-153: Move the default consent initialization to occur before
invoking the user callback so privacy defaults are in place prior to any
dataLayer/gtag calls; specifically, in google-tag-manager.ts set
opts.defaultConsent (the block that builds entries and calls gtag('consent',
'default', entry)) before calling options?.onBeforeGtmStart?.(gtag), ensuring
the existing logic that handles Array.isArray(opts.defaultConsent) and the gtag
calls remains unchanged aside from its new position.
In `@test/nuxt-runtime/consent-default.nuxt.test.ts`:
- Around line 255-273: The test compares dataLayer entries from
useScriptGoogleAnalytics but currently includes the gtag('js', new Date())
timestamp, making the assertion flaky; modify the runWith helper (used by the
test) to locate the 'js' entry (jsIdx) and remove or normalize the timestamp
argument (e.g. delete the second element or set it to a constant) from dl[jsIdx]
before slicing and returning so that fromObject and fromArray comparisons ignore
the timing-dependent payload.
- Around line 111-127: The test compares two GTM init payloads but fails
intermittently because the generated gtm.start timestamp (from Date.now())
differs; update the test around useScriptGoogleTagManager / runWith (the values
returned as dl and the gtm entry found via startIdx) to normalize the gtm.start
value before asserting equality—e.g., locate the gtm object in the sliced arrays
(the element with event === 'gtm.js' and property gtm.start) and set gtm.start
to a fixed number (or delete it) for both fromObject and fromArray so the
toEqual comparison is deterministic.
---
Nitpick comments:
In `@examples/regional-consent/package.json`:
- Around line 11-15: The dependency "@nuxt/scripts" in package.json is set to
the moving tag "latest"; replace that with a pinned version string (an exact
version like "x.y.z" or the same version used elsewhere in the repo) to ensure
reproducible installs—update the "@nuxt/scripts" entry to a fixed version
instead of "latest".
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 1f14c479-b78d-4a21-90b5-435ed8f100fd
📒 Files selected for processing (13)
docs/content/scripts/google-analytics.mddocs/content/scripts/google-tag-manager.mdexamples/regional-consent/app.vueexamples/regional-consent/assets/css/main.cssexamples/regional-consent/nuxt.config.tsexamples/regional-consent/package.jsonexamples/regional-consent/tsconfig.jsonpackages/script/src/registry-types.jsonpackages/script/src/runtime/registry/google-analytics.tspackages/script/src/runtime/registry/google-tag-manager.tspackages/script/src/runtime/registry/schemas.tspackages/script/src/runtime/types.tstest/nuxt-runtime/consent-default.nuxt.test.ts
|
Looks good, thanks! Are you able to take a look at coderabbit comments and fix if relevant + resolve them. |
- GTM `clientInit`: apply `defaultConsent` BEFORE `onBeforeGtmStart` so
custom events pushed by user callbacks honour the configured consent
state. Brings GTM in line with GA's existing ordering. Pre-existing
inconsistency surfaced during code review.
- Tests: drop the `+ 1` from the equivalence-test slices so the
`gtm.js` / `gtag('js', new Date())` timestamps are no longer compared.
The Date.now() / new Date() values can diverge across the two
back-to-back runWith calls, which would intermittently flake `toEqual`.
Ordering relative to those entries is locked by the sibling tests
already.
- GTM schema JSDoc: remove the trailing "See:" that introduced the
`@see` links — JSDoc parsers strip the @see lines from the description
and surface the dangling "See:" in `registry-types.json`.
- Regenerate `registry-types.json` to pick up the cleaned description.
Refs CodeRabbit review on PR nuxt#739.
|
Addressed CodeRabbit's review in
@coderabbitai please re-review. |
|
Tip For best results, initiate chat on the files or code changes.
Kicking off a fresh review now. [full_review] |
🔗 Linked issue
None — searched open and closed issues; no existing tracker for this.
❓ Type of change
📚 Description
Extends the
defaultConsentAPI introduced in #712 so thatuseScriptGoogleAnalyticsanduseScriptGoogleTagManageraccept an array of GCMv2 states, not just a single object. Each entry fires its owngtag('consent', 'default', entry)call, matching Google's documented multi-call pattern for region-specific consent.Backwards compatible: passing a single object behaves exactly as before. Single-entry arrays are observationally equivalent to the bare object (locked by a test). Empty arrays are a documented no-op.
What changed
Out of scope